import { BlockEnum, NodeDefault } from '@/components/workflow/types'
import { generateUUIDv4 } from '@/util/utils'
import { ALL_COMPLETION_AVAILABLE_BLOCKS } from '../../constants'
import { IntentNodeType } from './types'

export const getIntentDefaultParams = (): any => {
  return {
    model: {
      name: 'deepseek-r1',
      completion_params: {
        temperature: 0.3 // 温度
        // ResponseNum: 15 // 回复长度
      }
    },
    // 输入
    inputList: [
      {
        variable: 'query',
        value: undefined,
        type: 'cite',
        value_selector: []
      }
    ],
    /* 意图匹配 */
    recognizeList: [
      {
        variable: '',
        id: generateUUIDv4()
      }
    ],
    userInput: '', // 用户输入
    callWord: '', // 提示词
    // 输出
    outputList: [
      // {
      //   variable: 'output',
      //   value: '输出',
      //   type: 'string',
      //   value_selector: []
      // }
      {
        variable: 'id',
        value: 1,
        type: 'int',
        value_selector: []
      },
      {
        variable: 'reason',
        value: '输出',
        type: 'string',
        value_selector: []
      }
    ]
  }
}

const IntentDefault: NodeDefault<IntentNodeType> = {
  defaultValue: { ...getIntentDefaultParams() },
  getAvailablePrevNodes() {
    const nodes = ALL_COMPLETION_AVAILABLE_BLOCKS.filter(type => type !== BlockEnum.End)
    return nodes
  },
  getAvailableNextNodes() {
    const nodes = ALL_COMPLETION_AVAILABLE_BLOCKS
    return nodes
  },
  checkValid(payload: IntentNodeType) {
    let isValid = true
    let errorMessages = ''
    if (payload.type) {
      isValid = true
      errorMessages = ''
    }
    return {
      isValid,
      errorMessage: errorMessages
    }
  }
}

export default IntentDefault
